t = int(input())
for _ in range(t):
    # 第k个结点子节点范围[k*m+1-(m-1), k*m+1]
    n, m, k = map(int, input().split())
    l = k
    r = k
    ans = 1
    while 1:
        nl = l * m - m + 2
        nr = r * m + 1
        if nl > n:
            break
        ans += min(n, nr) - nl + 1
        l = nl
        r = min(n, nr)

    print(ans)
    
